package org.edu.modules.classSchedule.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.edu.common.api.vo.Result;
import org.edu.common.system.query.QueryGenerator;
import org.edu.modules.classSchedule.entity.VeJwPkmxClass;
import org.edu.modules.classSchedule.service.IVeJwPkmxClassService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.edu.common.system.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.edu.common.aspect.annotation.AutoLog;

/**
 * @Description: 排课明细
 * @Author:
 * @Date:   2021-05-13
 * @Version: V1.0
 */
@Api(tags="排课信息明细")
@RestController
@RequestMapping("/classSchedule/veJwPkmx")
@Slf4j
public class VeJwPkmxClassController extends BaseController<VeJwPkmxClass, IVeJwPkmxClassService> {
	@Autowired
	private IVeJwPkmxClassService veJwPkmxService;
	
	/**
	 * 分页查询
	 * @param veJwPkmx
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "排课明细-分页查询")
	@ApiOperation(value="明细查询", notes="排课明细-分页查询")
	@PostMapping(value = "/list")
	public Result<?> queryPageList(VeJwPkmxClass veJwPkmx,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="99") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<VeJwPkmxClass> queryWrapper = QueryGenerator.initQueryWrapper(veJwPkmx, req.getParameterMap());
		Page<VeJwPkmxClass> page = new Page<VeJwPkmxClass>(pageNo, pageSize);
		IPage<VeJwPkmxClass> pageList = veJwPkmxService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

     /**
      * 学生课表查询
      * @param req
      * @return
      */
     @AutoLog(value = "排课明细-学生课表查询")
     @ApiOperation(value="学生课表查询", notes="排课明细-学生课表查询")
     @PostMapping(value = "/studentSchedule")
	 @ApiImplicitParams({
			 @ApiImplicitParam(name = "stuid", value = "学生id", required = true),
			 @ApiImplicitParam(name = "semid", value = "学期id", required = true)
	 })
     public Result<?> studentSchedule(Integer stuid,
                                      Integer semid,
                                      HttpServletRequest req) {
		 VeJwPkmxClass veJwPkmx = new VeJwPkmxClass();
         QueryWrapper<VeJwPkmxClass> queryWrapper = QueryGenerator.initQueryWrapper(veJwPkmx, req.getParameterMap());
		 if(stuid!=null&& !stuid.equals("")) {
			 queryWrapper.eq("x.stuid", stuid);
		 }
		 if(semid!=null&& !semid.equals("")) {
			 queryWrapper.eq("p.semid", semid);
			 queryWrapper.eq("x.semid", semid);
		 }
         List<Map<String, Object>> list = veJwPkmxService.studentSchedule(queryWrapper);
         return Result.OK(list);
     }

	/**
	 * 教师课表查询
	 * @param req
	 * @return
	 */
	@AutoLog(value = "排课明细-教师课表查询")
	@ApiOperation(value="教师课表查询", notes="排课明细-教师课表查询")
	@PostMapping(value = "/teacherSchedule")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "teacherid", value = "教师id", required = true),
			@ApiImplicitParam(name = "semid", value = "学期id", required = true)
	})
	public Result<?> teacherSchedule(Integer teacherid,
									 Integer semid,
									 HttpServletRequest req) {
		VeJwPkmxClass veJwPkmx = new VeJwPkmxClass();
		QueryWrapper<VeJwPkmxClass> queryWrapper = QueryGenerator.initQueryWrapper(veJwPkmx, req.getParameterMap());
		if(teacherid!=null&& !teacherid.equals("")) {
			queryWrapper.eq("m.teacherid", teacherid);
		}
		if(semid!=null&& !semid.equals("")) {
			queryWrapper.eq("m.semid", semid);
		}
		List<Map<String, Object>> list = veJwPkmxService.teacherSchedule(queryWrapper);
		return Result.OK(list);
	}

	/**
	* 通过id查询
	* @param id
	* @return
	*/
	@AutoLog(value = "排课明细-通过id查询")
	@ApiOperation(value="通过id查询", notes="排课明细-通过id查询")
	@PostMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		VeJwPkmxClass veJwPkmx = veJwPkmxService.getById(id);
		if(veJwPkmx==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(veJwPkmx);
	}
	
	/**
	 * 新增信息
	 * @param veJwPkmx
	 * @return
	 */
	@AutoLog(value = "排课明细-新增信息")
	@ApiOperation(value="新增信息", notes="排课明细-新增信息")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody VeJwPkmxClass veJwPkmx) {
        veJwPkmx.setCreatetime(new Date());
		if(veJwPkmxService.save(veJwPkmx)){
		   return Result.OK("添加成功！");
        }
        return Result.error("添加失败!");
	}
	
	/**
	 * 修改信息
	 * @param veJwPkmx
	 * @return
	 */
	@AutoLog(value = "排课明细-修改信息")
	@ApiOperation(value="修改信息", notes="排课明细-修改信息")
	@PostMapping(value = "/edit")
	public Result<?> edit(@RequestBody VeJwPkmxClass veJwPkmx) {
        if(veJwPkmxService.updateById(veJwPkmx)){
		    return Result.OK("编辑成功!");
        }
        return Result.error("编辑失败!");
	}
	
	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "排课明细-通过id删除")
	@ApiOperation(value="通过id删除", notes="排课明细-通过id删除")
	@PostMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
        if(veJwPkmxService.removeById(id)){
		    return Result.OK("删除成功!");
        }
        return Result.error("删除失败!");
	}
	
	/**
	 * 批量删除
	 * @param pkId
	 * @return
	 */
	@AutoLog(value = "排课明细-批量删除")
	@ApiOperation(value="清空排课明细", notes="排课明细-批量删除")
	@PostMapping(value = "/deleteByPkId")
	public Result<?> deleteByPkId(@RequestParam(name="pkId",required=true) String pkId) {
		if(veJwPkmxService.deleteByPkId(pkId)){
		    return Result.OK("清空排课明细成功!");
        }
        return Result.error("清空排课明细失败!");
	}

	/**
	 * 周课表查询
	 * @return
	 */
	@AutoLog(value = "排课明细-周课表查询")
	@ApiOperation(value="周课表查询", notes="排课明细-周课表查询")
	@PostMapping(value = "/weekSchedule")
	public Result<?> weekSchedule1(@RequestParam(value = "bj_id",required = false) Integer bjId, @RequestParam(value = "teacherId",required = false)Integer teacherId,
								   Integer semId, Integer courseId,
								   HttpServletRequest req) {
		VeJwPkmxClass veJwPkmx = new VeJwPkmxClass();
		QueryWrapper<VeJwPkmxClass> queryWrapper = QueryGenerator.initQueryWrapper(veJwPkmx, req.getParameterMap());
		if(teacherId!=null&& !teacherId.equals("")) {
			queryWrapper.eq("m.teacherid", teacherId);
		}
		if(semId!=null&& !semId.equals("")) {
			queryWrapper.eq("m.semid", semId);
		}
		if(bjId!=null&& !bjId.equals("")) {
			queryWrapper.eq("p.jxbid", bjId);
		}
		if(courseId!=null&& !courseId.equals("")) {
			queryWrapper.eq("m.kcid", courseId);
		}
		List<Map<String, Object>> list = veJwPkmxService.weekSchedule(queryWrapper);
		return Result.OK(list);
	}
}
